﻿package mortal.game.view.copy.singleTowerCopy2.item
{
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.copy.singleTowerCopy2.data.*;
    import mortal.mvc.core.*;

    public class SingleTowerListCell extends GCellRenderer
    {
        protected var _bg:GImageBitmap;
        protected var _firstKill:GImageBitmap;
        protected var _item:BaseItem;
        protected var _getBtn:GLoadedButton;
        protected var _lvDes:GBitmap;
        protected var _lvTxt:BitmapNumberText;
        protected var _selectBg:ScaleBitmap;
        private var _obj:Object;

        public function SingleTowerListCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.gImageBitmap("SingleTowerIcon_56_1.png", 0, 0, this);
            this._firstKill = UIFactory.gImageBitmap(ImagesConst.CopyFirstKill_short, 131, 2, this);
            this._item = UIFactory.getUICompoment(BaseItem);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            UIFactory.setObjAttri(this._item, 140, 32, -1, -1, this);
            this._getBtn = UIFactory.gLoadedButton(ImagesConst.SigleTowerCopyFGet_upSkin, 185, 41, 36, 22, this);
            this._getBtn.label = "";
            this._lvDes = UIFactory.gBitmap(ImagesConst.SigleTowerCopyRwLvDes, 14, 16, this);
            this._lvTxt = UIFactory.bitmapNumberText(51, 13, "WorldBossNum.png", 25, 28, -12, this, 9, 1);
            this._lvTxt.text = "20";
            this._selectBg = UIFactory.bg(-2, -2, 235, 90, this, ImagesConst.ForgingSelectBg);
            this._getBtn.configEventListener(MouseEvent.CLICK, this.onGetRw);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._bg = null;
            this._firstKill = null;
            this._item = null;
            this._getBtn = null;
            this._lvDes = null;
            this._lvTxt = null;
            this._selectBg = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this.initInfo(param1);
            return;
        }// end function

        public function initInfo(param1:Object) : void
        {
            this._obj = param1;
            this._lvTxt.text = "" + param1.lv;
            this._bg.imgUrl = "SingleTowerIcon_" + param1.group + "_" + param1.lv + ".png";
            this.updateFrRw(param1);
            this.updateBtn(param1);
            var _loc_2:* = SingleTowerCopyUtil.getCanGetInLvByIndex(param1.code);
            if (_loc_2 == 0 && param1.lv == 1)
            {
                this.filters = null;
                this.showFirstRw(true);
            }
            else if (param1.lv <= (_loc_2 + 1))
            {
                this.filters = null;
            }
            else
            {
                this.filters = [FilterConst.colorFilter2];
            }
            if (param1.lv > _loc_2)
            {
                this.showFirstRw(true);
            }
            return;
        }// end function

        private function updateFrRw(param1:Object) : void
        {
            var _loc_3:ItemData = null;
            var _loc_2:* = SingleTowerCopyUtil.getFirstRwArrByCodeAndLv(param1.code, param1.lv);
            if (_loc_2 && _loc_2.length > 0)
            {
                _loc_3 = _loc_2[0];
                this._item.itemData = _loc_3;
            }
            return;
        }// end function

        public function updateBtn(param1:Object) : void
        {
            var _loc_2:* = Cache.instance.copy.groupTower.singleFtRwDic[param1.code];
            if (_loc_2 && _loc_2[param1.lv] == false)
            {
                this._getBtn.enabled = true;
                this._getBtn.filters = null;
                EffectManager.glowFilterReg(this._getBtn);
                this.showFirstRw(true);
            }
            else
            {
                this._getBtn.enabled = false;
                this._getBtn.filters = [FilterConst.colorFilter2];
                EffectManager.glowFilterUnReg(this._getBtn);
                this.showFirstRw(false);
            }
            return;
        }// end function

        private function showFirstRw(param1:Boolean) : void
        {
            var _loc_2:* = param1;
            this._item.visible = param1;
            var _loc_2:* = _loc_2;
            this._getBtn.visible = _loc_2;
            this._firstKill.visible = _loc_2;
            return;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            if (this._selectBg)
            {
                this._selectBg.visible = param1;
                if (param1)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.SingleTower2RightCopySelect, this._obj));
                }
            }
            return;
        }// end function

        public function flyIcon(param1:Object) : Boolean
        {
            var _loc_2:Point = null;
            if (param1.code == this._obj.code && param1.lv == this._obj.lv)
            {
                if (this._item && this._item.bitmapdata)
                {
                    _loc_2 = this._item.localToGlobal(GameConst.yellowPoint);
                    FlyToNavbarTool.flyBitmapOriginalToPack(this._item.bitmapdata, _loc_2);
                }
                return true;
            }
            return false;
        }// end function

        public function onGetRw(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.SingleTowerGetFirstRw, this._obj));
            return;
        }// end function

    }
}
